package com.top.mall.main.income

import android.app.Activity
import android.content.Intent
import android.graphics.Color
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import com.blankj.utilcode.util.BarUtils
import com.module.lemlin.owner.OwnerViewModeActivity
import com.top.mall.R
import com.top.mall.app.SPSConstance
import com.top.mall.jetpack.vm.CouponViewModel
import kotlinx.android.synthetic.main.activity_coupon_cash.*
import kotlinx.android.synthetic.main.activity_coupon_cash.imageViewBack

class CouponCashActivity : OwnerViewModeActivity<CouponViewModel>() {

    companion object {
        fun open(activity: Activity) {
            val intent = Intent(activity, CouponCashActivity::class.java)
            activity.startActivity(intent)
        }

        val tabs = mutableListOf("配送返还代金券", "积分兑换代金券", "团主返还代金券")
    }

//    private val couponCashGroupAdapter: CouponCashGroupAdapter = CouponCashGroupAdapter()

    override fun viewModel(): CouponViewModel {
        return createViewModel()
    }

    override val layoutResId: Int
        get() = R.layout.activity_coupon_cash

    override fun stateBar(): StatusBar {
        return StatusBar(color = R.color.colorWhite, view = flCouponCashBar)
    }

    override fun initView() {

        imageViewBack.setOnClickListener { finish() }

        val pagerAdapter = object : FragmentStatePagerAdapter(
            supportFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
        ) {
            override fun getItem(position: Int): Fragment =
                CouponCashFragment.newInstance(position)

            override fun getCount(): Int = tabs.size

            override fun getPageTitle(position: Int): CharSequence =
                tabs[position]

            override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {}
        }

        tabCouponCashKind.apply {
            for (item in tabs) {
                addTab(newTab().setText(item))
            }
        }.setupWithViewPager(vpCouponCashBody.apply {
            adapter = pagerAdapter
        })
//        rvCouponCashBody.apply {
//        }.adapter = couponCashGroupAdapter.apply {
//            addHeaderView(createHeader())
//        }

        SPSConstance.userInfo?.let {
            tvCouponCashPrice.text = it.cash_coupon_sum.toString()
        }
    }

    override fun initData() {

//        val groups: MutableList<String> = mutableListOf<String>()
//        for (index in 0..2) {
//            groups.add(index.toString())
//        }
//        couponCashGroupAdapter.setNewInstance(groups)
    }


    /**
     * 创建头布局
     * */
    private fun createHeader(): View {
        return this.layoutInflater.inflate(R.layout.item_coupon_cash_heads, null)
    }
}